package model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * This class represents a review object.
 * @author Rylie Nelson, Eric Preston
 */
public class Review implements Serializable {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -6836416796368763470L;

	/** 
	 * This array contains the ratings (1 - 5) for each of the 9 questions (indexed 0-8).
	 * It also contains a 10th rating (index 9) for the summary rating.
	 */
	private int[] rating;
	
	/** This is the rationale behind the ratings. */
	private List<String> reason;
	
	/** This is the user who provided this review. */
	private User reviewer;
	
	/**
	 * Constructor for a rating object.
	 * @param the_ratings the ratings for each of the 10 required questions
	 * @param the_reasons the rationale for each of the 10 required questions
	 * @param the_reviewer the user who provided this review
	 */
	public Review(int[] the_ratings, String[] the_reasons, User the_reviewer) {
		rating = the_ratings;		
		reason = new ArrayList<String>();
		for(String stat : the_reasons)
			reason.add(stat);
		reviewer = the_reviewer;
	}
	
	/**
	 * Returns the average score.
	 * @return the average score.
	 */
	public double averageScore() {
		double temp = 0;
		for(int i = 0; i < 9; i++) {
			temp += rating[i];
		}
		temp = temp/9;
		
		return temp;
	}
	
	/**
	 * Returns the rationale behind the rating.
	 * @return the rationale behind the rating.
	 */
	public List<String> getReasons() {
		return reason;
	}
	
	/**
	 * Returns the scores for each of the 10 questions.
	 * @return the socres for each of the 10 questions.
	 */
	public int[] getScores() {
		return rating;
	}
	
	/**
	 * Returns the user who provided this review.
	 * @return the user who provided this review.
	 */
	public User getReviewer() {
		return reviewer;
	}
	
	/**
	 * Returns the rating of this paper as a string.
	 * @return the rating.
	 */
	public String toString() {
		return ""+rating[9];
	}

}
